package com.xh.bussiness.system.controller;

import com.xh.bussiness.system.bean.dto.DictionaryTypeBean;
import com.xh.bussiness.system.service.IDictionaryTypeService;
import com.xh.bussiness.system.bean.request.DictionaryTypeRequest;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import org.springframework.validation.annotation.Validated;

import com.xh.core.controller.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author daiwei
 * @since 2018-10-17
 */
@Api(tags="数据字典分类")
@RestController
@RequestMapping("/system/dictionaryType")
public class DictionaryTypeController extends BaseController {

    @Autowired
    private IDictionaryTypeService dictionaryTypeService;

    /**
     * 分页数据查询
     * @param page 分页对象
     * @param bean 查询条件Bean
     * @return
     */
    @ApiOperation(value="数据字典分类数据分页查询", notes = "数据字典分类数据分页查询")
    @ApiImplicitParams({
            //@ApiImplicitParam(name="id", value="数据字典id", required = true, dataType = "String"),
    })
    @PostMapping("/queryPage")
    public XhPage queryPage(XhPage page, DictionaryTypeRequest bean){
        page=dictionaryTypeService.queryDictionaryTypePage(page,bean);
        return page;
    }

    /**
     * 数据查询
     * @param bean 查询条件Bean
     * @return
     */
    @ApiOperation(value="数据字典分类数据查询", notes = "数据字典分类数据查询")
    @ApiImplicitParams({
            //@ApiImplicitParam(name="id", value="数据字典id", required = true, dataType = "String"),
    })
    @PostMapping("/query")
    public AjaxResult query(DictionaryTypeRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"",dictionaryTypeService.queryDictionaryType(bean));
    }

    /**
     * 新增和保存
     * @param dictionaryTypeBean 实体对象
     * @return
     */
    @ApiOperation(value="数据字典分类数据保存", notes = "数据字典分类数据保存")
    @ApiImplicitParams({
            //@ApiImplicitParam(name="id", value="数据字典id", required = true, dataType = "String"),
    })
    @PostMapping(value="/saveOrUpdate")
    @Transactional
    public AjaxResult saveOrUpdate(@Validated DictionaryTypeBean dictionaryTypeBean){
        if(dictionaryTypeBean.getId()==null){
            dictionaryTypeService.insertObj(dictionaryTypeBean);
        }else{
            dictionaryTypeService.updateObj(dictionaryTypeBean);
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

    /**
     * 删除操作
     * @param id
     * @return
     */
    @ApiOperation(value="数据字典分类数据删除", notes = "数据字典分类数据删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id", value="数据字典分类id", required = true, dataType = "String"),
    })
    @PostMapping("/deleteById")
    @Transactional
    public AjaxResult deleteById(String id){
        dictionaryTypeService.delete(id);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }

    /**
     * 批量删除操作
     * @param ids
     * @return
     */
    @ApiOperation(value="数据字典分类数据删除", notes = "数据字典分类数据删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="ids", value="数据字典分类id集合", required = true, dataType = "Stirng[]"),
    })
    @PostMapping("/batchDelete")
    @Transactional
    public AjaxResult batchDelete(String[] ids){
        dictionaryTypeService.batchDelete(ids);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
    }
}

